<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head> 
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <title>会员管理</title>
	<link rel="stylesheet" href="../../../files/css/layui.css" media="all">
  <style>
    body{margin: 10px;}
    .demo-carousel{height: 300px; line-height: 300px; text-align: center;}
  </style>
</head>
<body>
	<div class="demoTable">
	  搜索用户名称：
	  <div class="layui-inline">
	    <input class="layui-input" name="memName" id="demoReload" autocomplete="off">
	  </div>
	  店长:
	  <div class="layui-inline"> 
	    <input class="layui-input" name="phone" id="linkman">
	  </div>
	  <button class="layui-btn" data-type="reload">搜索</button>
	  <button class="layui-btn" id="imgAdd" data-type="add">增加</button>
	</div> 
	<table class="layui-hide" id="test" lay-filter="demo"></table>
 
<script type="text/html" id="barDemo"> 
  <a class="layui-btn layui-btn-xs" lay-event="edit" id="imgUpdate">修改</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script type="text/html" id="switchIsva">
	 
	{{ panduan(d) }}
</script> 

<script src="../../../files/js/layui.js"></script> 
<script src="../../../commom/js/base.js"></script>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script>

var number = 0;
layui.use(['laydate', 'laypage', 'layer', 'table', 'upload', 'element'], function(){
  var laydate = layui.laydate //日期
  ,laypage = layui.laypage //分页
  layer = layui.layer //弹层
  ,table = layui.table //表格
  ,upload = layui.upload //上传
  ,element = layui.element; //元素操作
 
  
  //执行一个 table 实例
  table.render({
     elem: '#test'
    ,height: 474
    ,url: getRootPath()+'shop/findVague.action' //数据接口
    ,page: true //开启分页
    ,method:'post'
    ,cols: [[ //表头
       {type:'checkbox', fixed: 'left'}
      ,{field: 'shopId', title: '会员编号', width:120, fixed: 'left'}
      ,{field: 'shopName', title: '会员名称', width:120,align:'center'}
      ,{field: 'shopSite', title: '地址',width:120,align:'center'} //templet:'<div><img src="{{ d.goodsImageAddress}}" style="width:40px; height:30px;"></div>'
      ,{field: 'linkman', title: '店长', width:120,align:'center'} 
      ,{field: 'isva', title: '是否有效', width: 170,align:'center',templet:'#switchIsva', unresize : true} 
      ,{field: 'phone', title: '号码', width: 170,align:'center'} 
      ,{field: 'optime', title: '操作时间', width: 170,align:'center'} 
      ,{field: 'oper', title: '操作人', width: 170,align:'center',} 
      ,{field: 'shopCost', title: '配送费', width: 170,align:'center',} 
      ,{field: 'sort', title: '是否排序', width: 170,align:'center',} 
      ,{field: 'typeName', title: '类型名称', width: 170,align:'center',} 
      ,{field: 'fileName', title: '图片', width: 170,align:'center',templet:'<div><img  src="{{ d.fileName}}" style="width:40px; height:30px;"></div>'} 
      ,{fixed: 'right',title: '操作', width: 165, align:'center', toolbar: '#barDemo'}
    ]]
  	,id: 'testReload'
  	 
  });
  
  
  
  
  //监听工具条
  table.on('tool(demo)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
    var data = obj.data //获得当前行数据
    ,layEvent = obj.event; //获得 lay-event 对应的值
   // alert(data); 
      
    if(layEvent === 'del'){
      var id=data.shopId; //得到当前行ID
      layer.confirm('确认删除？', function(index){
      
        layer.close(index);
        //使用jquery的ajax方式向后台提交数据
		var url = getRootPath()+'shop/delete.action';
		var data={shopId:id};
			$.post(url,data,function(data){
				  obj.del(); //删除对应行（tr）的DOM结构
				if(data.num>0){
					layer.msg(data.msg, {
						  icon: 1,
						  time: 1000 //1秒关闭（如果不配置，默认是3秒）
						}, function(){
						  
					});
				}
				
			},"JSON");
      	});
    } else if(layEvent === 'edit'){
    	
    	var id=data.shopId;
        alert("这里 "+id);
        //使用jquery的ajax方式向后台提交数据
		var url = getRootPath()+'shop/showUpdate.action';
		var data={shopId:id};
		$.post(url,data,function(data){
		//转换成JSon格式
		//eval("var shop="+data);
		
		 layer.open({
			  type: 2,
			  area : ['60%' , '90%'],//弹出框大小
			  shift:1,//弹出框动画效果
			  content: ['../../../page/background/shop/update.html','on'], //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
		 	  success:function(layero,index){
		 		  var body = layer.getChildFrame('body',index);//确定两个页面之间的父子关系
		 		  var iframeWin = window[layero.find('iframe')[0]['name']];//子页面对象
		 		  console.log(body.html()) //得到iframe页的body内容
		 		  //通过id或者class获取子页面的元素对象进行赋值
		 		  body.find("#typeId").val(data.typeId);
		 		  body.find("#shopId").val(data.shopId);
		 		  body.find("#shopName").val(data.shopName); 
		 		  //body.find("#imgs").attr('src',goimg.phone);
		 		  body.find("#phone").val(data.phone);
		 		 body.find("#isva").val(data.isva);
		 		 body.find("#linkman").val(data.linkman); 
		 		 body.find("#sort").val(data.sort); 
  
		 		 body.find("#shopCote").val(data.shopCote);
		 		// body.find("#fileName").val('../../'+data.fileName); 
		 		 body.find("#image").attr('src',data.fileName);
		 		  body.find(".layui-textarea").val(data.shopSite);
		 		  
		 		   
		 	  }
			}); 
			   
		},"JSON");
    } else if(layEvent === 'shenhe'){
    	 
    	 layer.confirm('确认执行？', function(index){
    	      
    	        layer.close(index);
    	        //使用jquery的ajax方式向后台提交数据
    			 var url = getRootPath()+"shop/isvaUp.action";
    		var id = data.shopId;
    		 //var shop = JSON.stringify(data);
    		 
    		var datas ={shopId:id};
    		$.post(url,datas,function(data){
    			if(data.num>0){
					layer.msg(data.msg, {
						  icon: 1,
						  time: 1000 //1秒关闭（如果不配置，默认是3秒）
						}, function(){ 
							number = data.num;
							manAdd(number);
							 table.reload('testReload', {
							       page: {
							         curr: 1 //重新从第 1 页开始
							       }
							       
							     });
					});
				}
    		})
    	      	});
    		
    	
    }
  });
  
  //条件查询
  //获取jquery的$
  var $ = layui.$;
		  
  $('.demoTable .layui-btn').on('click', function(){
	 var demoReload = $('#demoReload');
	 //执行重载
     table.reload('testReload', {
       page: {
         curr: 1 //重新从第 1 页开始
       }
       ,where: {
    	  linkman:$("#linkman").val(),
          shopName: demoReload.val()
       }
     });
  });
  $('#imgAdd').on('click', function(){
	 layer.open({
		  type: 2,
		  area : ['60%' , '90%'],//弹出框大小
		  shift:1,//弹出框动画效果
		  content: ['../../../page/background/shop/add.html','on'] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
		}); 
   });
  
});
  
  //是否有效
  function panduan(d){
	  var html="";
	  if(d.isva==0){
		  html='<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="shenhe">审核</a>';
	  }else if(d.isva>0){
		  html='<a class="layui-btn layui-btn-xs" >已审核</a>';
	  } 
	  return html ;
  }
  
  function manAdd(num){
	  if(num>0){
		  var url = getRootPath()+"manager/add.action";
		  $.post(url,null,function(msg){
			 //alert(" 信息 "+msg.msg);
			 
		  },"JSON")
	  }
	  
  }
   
</script>
</body>
</html>   